- 被度(調査面積に対する対象植物の被覆度)は、もともとは0〜1の範囲の連続値。
- 実際には、{+, 1, 2, 3, 4, 5}などといった階級データとして記録されることが多い。
- また、測定値は目視で決められることが多い。
https://github.com/ito4303/jfs131 で公開しています。
被度(連続値)は0〜1の値をとるので、ベータ分布にあてはめるのは自然な発想。
\[ y \sim \mathrm{Beta}(\alpha, \beta) \]
平均\(\mu\)を使ったパラメータ化
\[ y \sim \mathrm{Beta}\left(\frac{\mu}{\delta}-\mu,\frac{(1-\mu)(1-\delta)}{\delta}\right) \]
\(\delta\)はもともと、pin-point法による被度測定における方形区内の分布相関 (Damgaard 2012)
しかし、被度測定における不確実性とも解釈可能。
今回は以下のように定義する。
1: 0–0.01 (0を含む), 2: 0.01–0.1, 3: 0.1–0.25, 4: 0.25–0.5, 5: 0.5–0.75, 6: 0.75–1
\(\delta\)を変化させたとき、実際の被度に対して、各被度階級が選ばれる確率を図示する。
生成されたデータ
## [1] 5 5 5 5 4 5 5 5 5 5
被度階級の確率分布を関数として定義
functions {
real coverclass_lpmf(int Y, vector CP, real a, real b) {
int n_cls;
real gamma;
n_cls = num_elements(CP) + 1;
if (Y <= 1) { // 0 or 1
gamma = inc_beta(a, b, CP[1]);
} else if(Y >= 2 && Y < n_cls) {
gamma = inc_beta(a, b, CP[Y])
- inc_beta(a, b, CP[Y - 1]);
} else {
gamma = 1 - inc_beta(a, b, CP[n_cls - 1]);
}
return bernoulli_lpmf(1 | gamma);
}
}
モデルの定義
model {
{
real a = p / delta - p;
real b = (1 - p) * (1 - delta) / delta;
for (n in 1:N)
Y[n] ~ coverclass(CP, a, b);
}
}
\(\mu\)のところをpにした。
## Inference for Stan model: cover-202001312030-1-22d8b6.
## 4 chains, each with iter=2000; warmup=1000; thin=1;
## post-warmup draws per chain=1000, total post-warmup draws=4000.
##
## mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
## p 0.59 0 0.04 0.51 0.56 0.59 0.61 0.67 1619 1
## delta 0.04 0 0.03 0.00 0.02 0.03 0.05 0.11 1819 1
##
## Samples were drawn using NUTS(diag_e) at 金 1 31 20時30分10秒 2020.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).
とくに矛盾はない
次式で被度が生成される。 \[ \mathrm{logit}(p) = -5 + 5 X + \epsilon \\ \epsilon \sim \mathrm{Normal}(0, \sigma) \]
被度pをロジットリンクで線形予測子と結びつける
transformed parameters {
vector<lower = 0, upper = 1>[N] p; // proportion of cover
p = inv_logit(beta[1] + beta[2] * X + sigma * err);
}
モデルの定義
model {
// Observation
for (n in 1:N) {
real a = p[n] / delta - p[n];
real b = (1 - p[n]) * (1 - delta) / delta;
for (r in 1:R)
Y[n, r] ~ coverclass(CP, a, b);
}
// System
err ~ std_normal();
sigma ~ normal(0, 5);
}
## Inference for Stan model: cover2-202001312030-1-fe81b1.
## 4 chains, each with iter=2000; warmup=1000; thin=1;
## post-warmup draws per chain=1000, total post-warmup draws=4000.
##
## mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
## delta 0.13 0.00 0.03 0.08 0.10 0.12 0.14 0.19 1232 1
## beta[1] -4.76 0.01 0.45 -5.66 -5.05 -4.75 -4.45 -3.93 1665 1
## beta[2] 4.73 0.01 0.66 3.45 4.28 4.72 5.17 6.08 2067 1
## sigma 0.59 0.01 0.23 0.10 0.45 0.61 0.75 1.00 680 1
##
## Samples were drawn using NUTS(diag_e) at 金 1 31 20時31分45秒 2020.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).
1回目の測定について表示
モデルの定義
model {
// Observation model
for (n in 1:N) {
real a = p[n] / delta - p[n];
real b = (1 - p[n]) * (1 - delta) / delta;
if (sum(Y[n]) == 0) { // Y[n]==0 for all n
real lp[2];
lp[1] = bernoulli_lpmf(0 | omega);
lp[2] = bernoulli_lpmf(1 | omega)
+ coverclass_lpmf(1 | CP, a, b) * R
+ bernoulli_lpmf(0 | psi) * R;
target += log_sum_exp(lp);
} else {
つづく
for (r in 1:R) {
if (Y[n, r] == 0) {
target += bernoulli_lpmf(1 | omega)
+ coverclass_lpmf(1 | CP, a, b)
+ bernoulli_lpmf(0 | psi);
} else if (Y[n, r] == 1) {
target += bernoulli_lpmf(1 | omega)
+ coverclass_lpmf(1 | CP, a, b)
+ bernoulli_lpmf(1 | psi);
} else {
target += bernoulli_lpmf(1 | omega)
+ coverclass_lpmf(Y[n, r] | CP, a, b);
}
}
}
}
## Inference for Stan model: zicover-202001312032-1-bbb428.
## 4 chains, each with iter=2000; warmup=1000; thin=1;
## post-warmup draws per chain=1000, total post-warmup draws=4000.
##
## mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
## delta 0.14 0.00 0.03 0.08 0.11 0.13 0.16 0.22 2145 1
## omega 0.82 0.00 0.04 0.72 0.79 0.82 0.85 0.90 4948 1
## psi 0.75 0.00 0.12 0.49 0.68 0.77 0.84 0.93 4179 1
## beta[1] -4.73 0.01 0.54 -5.88 -5.07 -4.69 -4.35 -3.76 1793 1
## beta[2] 4.40 0.02 0.77 2.98 3.89 4.35 4.88 6.05 1943 1
## sigma 0.45 0.01 0.25 0.04 0.26 0.44 0.63 0.98 1055 1
##
## Samples were drawn using NUTS(diag_e) at 金 1 31 20時32分54秒 2020.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).
10×10=100個の方形区で、被度を生成する
↓
被度階級に変換
隣とは近い値をとる
Exact sparse CAR models in Stan by Max Joseph
https://mc-stan.org/users/documentation/case-studies/mbjoseph-CARStan.html
phiの逆ロジットが被度p
transformed parameters {
vector[N] p = inv_logit(phi);
}
sparse_iarで、空間自己相関の事前分布
model {
// Spatial random effects
phi ~ sparse_iar(tau, W_sparse, D_sparse, lambda, N, W_n);
// Observation model
for (n in 1:N) {
real a = p[n] / delta - p[n];
real b = (1 - p[n]) * (1 - delta) / delta;
Y[n] ~ coverclass(CP, a, b);
}
// Priors
tau ~ gamma(2, 2);
}
## Inference for Stan model: carcover-202001312033-1-5ed611.
## 4 chains, each with iter=8000; warmup=4000; thin=1;
## post-warmup draws per chain=4000, total post-warmup draws=16000.
##
## mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
## delta 0.02 0.00 0.01 0.01 0.01 0.02 0.02 0.04 4472 1
## tau 1.69 0.01 0.58 0.84 1.27 1.60 2.02 3.10 2703 1
##
## Samples were drawn using NUTS(diag_e) at 金 1 31 20時36分47秒 2020.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at
## convergence, Rhat=1).